class Item < ActiveRecord::Base
  belongs_to :event
  has_many :votes
  has_many :participants, :dependent => :destroy
  @@children = []
  
  def self.inherited(sub)
    @@children << sub
  end
  
  def self.children
    return @@children
  end
  
  def has_role?(person, role)
    self.participants.each do | part |
      return true if person.id == part.person_id and role.downcase == part.role.downcase
    end
    return false
  end
  
  def clear_role(role)
    entries = []
    self.participants.each do | part |
      entries << part if part.role.downcase == role.downcase
    end
    self.participants.delete(entries) unless entries.empty?
  end
end
